package com.wnxy.sddfp.system.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.wnxy.sddfp.client.bank.TestBankApi;
import com.wnxy.sddfp.system.service.impl.MyServiceTestImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private TestBankApi testBankApi;

    /**
     * 测试：OpenFeign集成Sentinel做流控
     */
    @GetMapping("/show/{bankId}")
    public String hello(@PathVariable("bankId") Integer bankId) {
        return testBankApi.findBankByIdTest(bankId);
    }

    @GetMapping("/list")
    public String list(){
        return "list";
    }


    @Autowired
    private MyServiceTestImpl myService;

    @GetMapping("/check")
    public String check(){
        return myService.doSomething();
    }

    @GetMapping("/check1")
    public String check1(){
        return myService.doSomething();
    }

    @GetMapping("/product")
    @SentinelResource(value="getProductById",fallback="exceptionHandler")
    public String getProductById(@RequestParam("id") long id){
        return "product:"+id;
    }

    public String exceptionHandler(@RequestParam("id") long id){
        return "热点参数限流";
    }
}